using System.Collections.Specialized;
using System.ComponentModel;
using EnvDTE;
using Microsoft.Practices.RecipeFramework.Library.Converters;
using Microsoft.Practices.RecipeFramework.Library.Editors;
using Microsoft.Practices.WizardFramework;
using Microsoft.VisualStudio.Shell;
using VSShellAssist.Recipes.Common.CustomPages;

namespace VSShellAssist.Recipes.CreateSetupProject
{
	/// <summary>
    /// Custom page for CreateSetupProjectCP recipe
	/// </summary>
	public partial class CreateSetupProjectCP : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="CreateSetupProjectCP"/> class.
		/// </summary>
        public CreateSetupProjectCP()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CreateSetupProjectCP"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public CreateSetupProjectCP(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
		}

        [RecipeArgument]
        public Project VSShellProject
        {
            get { return (Project)veVSShellProject.Value; }
            set
            {
                if(value != null)
                {
                    veVSShellProject.TextBox.Text = new ProjectConverter().ConvertTo(value, typeof(string)) as string;
                }
            }
        }

        [RecipeArgument]
        public ProjectItem DefFileProjectItem
        {
            get { return (ProjectItem)vePkgDefFile.Value; }
            set
            {
                if(value != null)
                {
                    vePkgDefFile.TextBox.Text = new ProjectItemConverter().ConvertTo(value, typeof(string)) as string;
                }
            }
        }

        [RecipeArgument]
        public string Manufacturer
        {
            get { return veManufacturer.Value.ToString(); }
            set
            {
                if(value != null)
                {
                    veManufacturer.TextBox.Text = value;
                }
            }
        }

        [RecipeArgument]
        public string ProductNameArgument
        {
            get { return veProductName.Value.ToString(); }
            set
            {
                if(value != null)
                {
                    veProductName.TextBox.Text = value;
                }
            }
        }

        [RecipeArgument]
        public string Description
        {
            get { return veDescription.Value.ToString(); }
            set
            {
                if(value != null)
                {
                    veDescription.TextBox.Text = value;
                }
            }
        }

        [RecipeArgument]
        public string Comments
        {
            get { return veComments.Value.ToString(); }
            set
            {
                if(value != null)
                {
                    veComments.TextBox.Text = value;
                }
            }
        }

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
                    this.veVSShellProject.BeginInit();
                    this.veVSShellProject.ValueType = typeof(Project);
                    base.Site.Container.Add(veVSShellProject);
                    SolutionPickerEditor solutionPickerEditor1 = new SolutionPickerEditor();
                    StringDictionary solutionPickerEditorAttributes1 = new StringDictionary();
                    solutionPickerEditorAttributes1.Add("UnboundReferenceType", "VSShellAssist.Recipes.Common.References.VSShellProjectReference, VSShellAssist");
                    solutionPickerEditor1.Configure(solutionPickerEditorAttributes1);
                    this.veVSShellProject.EditorInstance = solutionPickerEditor1;
                    this.veVSShellProject.ConverterInstance = new ProjectConverter();
                    this.veVSShellProject.EndInit();

                    this.vePkgDefFile.BeginInit();
                    this.vePkgDefFile.ValueType = typeof(ProjectItem);
                    base.Site.Container.Add(vePkgDefFile);
                    SolutionPickerEditor solutionPickerEditor = new SolutionPickerEditor();
                    StringDictionary solutionPickerEditorAttributes = new StringDictionary();
                    solutionPickerEditorAttributes.Add("UnboundReferenceType", "VSShellAssist.Recipes.Common.References.PkgDefProjectItemReference, VSShellAssist");
                    solutionPickerEditor.Configure(solutionPickerEditorAttributes);
                    this.vePkgDefFile.EditorInstance = solutionPickerEditor;
                    this.vePkgDefFile.ConverterInstance = new ProjectItemConverter();
                    this.vePkgDefFile.EndInit();

                    this.veManufacturer.BeginInit();
                    this.veManufacturer.ValueType = typeof(string);
                    base.Site.Container.Add(veManufacturer);
                    this.veManufacturer.EndInit();

                    this.veProductName.BeginInit();
                    this.veProductName.ValueType = typeof(string);
                    base.Site.Container.Add(veProductName);
                    this.veProductName.EndInit();

                    this.veDescription.BeginInit();
                    this.veDescription.ValueType = typeof(string);
                    base.Site.Container.Add(veDescription);
                    this.veDescription.EndInit();

                    this.veComments.BeginInit();
                    this.veComments.ValueType = typeof(string);
                    base.Site.Container.Add(veComments);
                    this.veComments.EndInit();
				}
			}
		}

        private void veManufacturer_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            string manufacturer = veManufacturer.Value as string;
            DictionaryService.SetValue("Manufacturer", manufacturer);
        }

        private void veProductName_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            string productName = veProductName.Value as string;
            DictionaryService.SetValue("ProductNameArgument", productName);
        }

        private void veDescription_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            string description = veDescription.Value as string;
            DictionaryService.SetValue("Description", description);
        }

        private void veComments_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            string comments = veComments.Value as string;
            DictionaryService.SetValue("Comments", comments);
        }

        private void veVSShellProject_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            Project project = (Project)veVSShellProject.Value;
            DictionaryService.SetValue("VSShellProject", project);
        }

        private void vePkgDefFile_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
        {
            ProjectItem projectItem = (ProjectItem)vePkgDefFile.Value;
            DictionaryService.SetValue("DefFileProjectItem", projectItem);
        }
	}
}